class PlaylistsController < ApplicationController
  before_action :exception_stb, only: [:show]

  def index
    # 样式原因, 保持上下分离
    collection = Playlist.ordered
    @playlist_rows = if collection.present?
                       if collection.count >= 11
                         collection.each_slice((collection.count / 2.0).ceil)
                       else
                         collection.each_slice(5)
                       end
                     else
                       []
                     end
  end

  def show
    # 访问歌单, 访问量 + 1
    @playlist = Playlist.includes(:songs).find(params[:id])
    @playlist.update(view_amount: @playlist.view_amount + 1)

    @fav_playlists = current_user.playlists
    @picks = current_user.picklist.songs.pluck(:id)
    @favs = current_user.song_fav.songs.pluck(:id)
  end
end
